package reese.think_in_java.java_21_thread;

/**
 * ***********************************************************
 *
 * @类名 : reese.think_in_java.java_21_thread.类名
 * @DESCRIPTION : 这家伙太懒啥都没写
 * @AUTHOR :  一个风情万种的男子
 * @DATE : 2016/5/29
 * ***********************************************************
 */


//understanding join()
class Sleeper extends Thread {
    private int duration;//期间的意思

    public Sleeper(String name, int sleepTime) {
        super(name);
        duration = sleepTime;
        start();
    }

    public void run() {
        try {
            sleep(duration);
        } catch (InterruptedException e) {
            System.out.println(getName() + " was interrupted.." +
                " isInterrupted(): " + isInterrupted()
            );
            return;
        }
        System.out.println(getName() + " has awakened...");

    }

}

class Joiner extends Thread {
    private Sleeper sleeper;
    public  Joiner(String name,Sleeper sleeper){
        super(name);
        this.sleeper = sleeper ;
        start();
    }
    public void run(){
        try {
            sleeper.join();
        } catch (InterruptedException e) {
            System.out.println("Interrupted");
        }
        System.out.println(getName() + " join completed ...");
    }
}


public class Joining {
    public static void main(String[] args) {
        Sleeper sleepy = new Sleeper("sleepy",1500),
                grumpy = new Sleeper("grumpy",1500);
        Joiner dopey = new Joiner("dopey",sleepy),
                doc = new Joiner("doc",grumpy);

        grumpy.interrupt();
    }

}
